package mesweb.mesweb.service.impl.procedure;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import mesweb.mesweb.dto.Procedure.ProductProduceProcedureDto;
import mesweb.mesweb.dto.ProducePlan.ProduceLineBottleneckDto;
import mesweb.mesweb.entity.Procedure.MesProcedure;
import mesweb.mesweb.entity.Procedure.MesProductProcedureBranchProcedure;
import mesweb.mesweb.mapper.procedure.MesProductProcedureBranchProcedureMapper;
import mesweb.mesweb.service.procedure.IMesProductProcedureBranchProcedureService;
import mesweb.mesweb.vo.procecdure.MesProductProcedureBranchProcedureVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 生产支线工序关系
 * @Author: jeecg-boot
 * @Date:   2021-06-26
 * @Version: V1.0
 */
@Service
public class MesProductProcedureBranchProcedureServiceImpl extends ServiceImpl<MesProductProcedureBranchProcedureMapper, MesProductProcedureBranchProcedure> implements IMesProductProcedureBranchProcedureService {

    @Autowired
    private  MesProductProcedureBranchProcedureMapper mesProductProcedureBranchProcedureMapper;
    @Override
    public IPage<MesProductProcedureBranchProcedureVo> getProductProcedureBranchProcedure(Page page, QueryWrapper queryWrapper) {
        return mesProductProcedureBranchProcedureMapper.getProductProcedureBranchProcedure(page,queryWrapper);
    }

    @Override
    public List<MesProductProcedureBranchProcedureVo> getProductProcedureBranchProcedure(QueryWrapper queryWrapper) {
        return mesProductProcedureBranchProcedureMapper.getProductProcedureBranchProcedure(queryWrapper);
    }

    @Override
    public IPage<MesProcedure> getProductProcedureProcedures(Page page, ProductProduceProcedureDto productProduceProcedureDto) {
        return mesProductProcedureBranchProcedureMapper.getProductProcedureProcedures(page,productProduceProcedureDto);
    }

    @Override
    public List<MesProcedure> getProductProcedureProcedures(ProductProduceProcedureDto productProduceProcedureDto) {
        return mesProductProcedureBranchProcedureMapper.getProductProcedureProcedures(productProduceProcedureDto);
    }

    @Override
    public List<MesProcedure> getBottleneckProcedure(ProduceLineBottleneckDto productProduceProcedureDto) {

        List<MesProcedure> result  = new ArrayList<>();
        //获取所有的排产计划的瓶颈工序
        if( null ==  productProduceProcedureDto || productProduceProcedureDto.getSourceType() != 1 && productProduceProcedureDto.getSourceType() != 2)
        {
            productProduceProcedureDto.setSourceType(1);
            List<MesProcedure> tmp  = mesProductProcedureBranchProcedureMapper.getBottleneckProcedure(productProduceProcedureDto);
            if( null != tmp)
            {
                result.addAll(tmp);
            }
            productProduceProcedureDto.setSourceType(2);
            tmp  = mesProductProcedureBranchProcedureMapper.getBottleneckProcedure(productProduceProcedureDto);
            if( null != tmp)
            {
                result.addAll(tmp);
            }
        }
        else
        {
            result  = mesProductProcedureBranchProcedureMapper.getBottleneckProcedure(productProduceProcedureDto);
        }
        return result;
    }
}
